# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>

pkgname=shairport-sync
pkgver=4.3.2
pkgrel=1
pkgdesc='Emulates an AirPort Express for the purpose of streaming music from iTunes and compatible iPods and iPhones'
url='https://github.com/mikebrady/shairport-sync'
arch=(loong64 x86_64)
license=(GPL)
backup=(etc/shairport-sync.conf)
depends=(openssl avahi libsoxr popt alsa-lib libconfig libpulse jack mosquitto)
makedepends=(xmltoman vim) # vim for xxd tool
source=(shairport-sync-$pkgver.zip::https://github.com/mikebrady/shairport-sync/archive/$pkgver.zip
        shairport-sync.sysusers
        remove_useradd.patch)
sha256sums=('7d11385073d5bc56f1abf704cdd10388f101fc1f04b1a6051a964d7ce14f2aeb'
            'bc2d92254910996e837d1c4c7dd81eddfb96a9f5f0cb2faad9fcb0414ea79a1d'
            '3973049b1a92c729efacd3312636a8c7f3d51cd62c7d5af214668c8104378dc6')

prepare() {
  cd shairport-sync-$pkgver

  patch -p1 < ../remove_useradd.patch
}

build() {
  cd shairport-sync-$pkgver

  autoreconf -i -f
  ./configure --prefix=/usr --sysconfdir=/etc --with-alsa --with-pa --with-avahi --with-jack --with-stdout --with-pipe --with-ssl=openssl --with-soxr --with-dns_sd --with-pkg-config --with-systemd --with-configfiles --with-metadata --with-mqtt-client
  make

  sed 's|/usr/local/bin/|/usr/bin/|' -i scripts/shairport-sync.service.in
}

package() {
  cd shairport-sync-$pkgver
  make DESTDIR="$pkgdir" install
  install -D -m644 "$srcdir"/shairport-sync.sysusers "$pkgdir"/usr/lib/sysusers.d/shairport-sync.conf
  install -D -m664 LICENSES "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  rm "$pkgdir"/etc/shairport-sync.conf.sample
}
